package com.ruoyi.web.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Y·C
 * @version 1.0.0
 * @ClassName CarouselFrontControl.java
 * @Description TODO
 * @createTime 2024年02月23日 14:35:00
 */
@Api(tags = "前台接口")
@RestController
@RequestMapping("/carouselFront")
public class CarouselFrontControl extends BaseController {

    @Autowired
    private ICarouselService carouselService;

    @Autowired
    private ISpotsService spotService;

    @Autowired
    private ITravelGuideService travelGuideService;

    @Autowired
    private IRoutesService routesService;

    @Autowired
    private IHotelsService hotelsService;

    @Autowired
    private INoticeService noticeService;

    @Autowired
    private ISpotsOrderService spotsOrderService;
    @Autowired
    private IHotelsOrderService hotelsOrderService;




    @Anonymous
    @ApiOperation(value = "获取轮播图列表")
    @GetMapping("/list")
    public AjaxResult list() {
        LambdaQueryWrapper<Carousel> carouselLambdaQueryWrapper = new LambdaQueryWrapper<>();
        carouselLambdaQueryWrapper.eq(Carousel::getStatus, 1);
        return AjaxResult.success(carouselService.list(carouselLambdaQueryWrapper));
    }

    @Anonymous
    @ApiOperation(value = "获取热门景点")
    @GetMapping("/hot")
    public AjaxResult hot() {
        LambdaQueryWrapper<Spots> spotsLambdaQueryWrapper = new LambdaQueryWrapper<>();
        spotsLambdaQueryWrapper.eq(Spots::getStatus, 1);
        //按照景点评分排序
        spotsLambdaQueryWrapper.orderByDesc(Spots::getSpotRating);
        List<Spots> list = spotService.list(spotsLambdaQueryWrapper);
        //找出集合中的前三个
        List<Spots> spotsList = list.subList(0, 4);
        return AjaxResult.success(spotsList);

    }

    @Anonymous
    @ApiOperation(value = "获取景点列表")
    @GetMapping("/spotsList/{id}")
    public TableDataInfo spotsList(@PathVariable Long id) {

        if (id == 1L) {
            //景点
            startPage();
            LambdaQueryWrapper<Spots> spotsLambdaQueryWrapper = new LambdaQueryWrapper<>();
            spotsLambdaQueryWrapper.eq(Spots::getStatus, 1);
            List<Spots> list = spotService.list(spotsLambdaQueryWrapper);
            return getDataTable(list);
        }else if (id== 2L){
            //旅游攻略travelGuideService
            startPage();
            LambdaQueryWrapper<TravelGuide> spotsLambdaQueryWrapper = new LambdaQueryWrapper<>();
            spotsLambdaQueryWrapper.eq(TravelGuide::getStatus, 1);
            List<TravelGuide> list = travelGuideService.list(spotsLambdaQueryWrapper);
            return getDataTable(list);
        }else if (id== 3L){
            //路线
            startPage();
            return getDataTable(routesService.list());
        }else if (id== 4L){
            //酒店
            startPage();
            return getDataTable(hotelsService.list());
        }
        return null;

    }


    @Anonymous
    @ApiOperation(value = "获取攻略详细")
    @GetMapping("/guideDetail/{id}")
    public AjaxResult guideDetail(@PathVariable Long id) {
        return AjaxResult.success(travelGuideService.getById(id));
    }

    @Anonymous
    @ApiOperation(value = "获取路线详细")
    @GetMapping("/routesDetail/{id}")
    public AjaxResult routesDetail(@PathVariable Long id) {
        return AjaxResult.success(routesService.getById(id));
    }

    @Anonymous
    @ApiOperation(value = "获取酒店详细")
    @GetMapping("/hotelsDetail/{id}")
    public AjaxResult hotelsDetail(@PathVariable Long id) {
        return AjaxResult.success(hotelsService.getById(id));
    }

    @Anonymous
    @ApiOperation(value = "获取景点详细")
    @GetMapping("/spotsDetail/{id}")
    public AjaxResult spotsDetail(@PathVariable Long id) {
        return AjaxResult.success(spotService.getById(id));
    }

    @Anonymous
    @ApiOperation(value = "景点订单列表")
    @GetMapping("/spotsOrderList")
    public TableDataInfo spotsOrderList() {
        startPage();
        // /** 订单状态，1：未支付；2：已支付；3：已核销；4：已取消；5：退款中；6：已退款 */
        List<SpotsOrder> list = spotsOrderService.list();
        list.forEach(spotsOrder -> {
            if (spotsOrder.getStatus().equals("1")){
                spotsOrder.setStatus("未支付");
            }else if (spotsOrder.getStatus().equals("2")){
                spotsOrder.setStatus("已支付");
            }else if (spotsOrder.getStatus().equals("3")){
                spotsOrder.setStatus("已核销");
            }else if (spotsOrder.getStatus().equals("4")){
                spotsOrder.setStatus("已取消");
            }else if (spotsOrder.getStatus().equals("5")){
                spotsOrder.setStatus("退款中");
            }else if (spotsOrder.getStatus().equals("6")){
                spotsOrder.setStatus("已退款");
            }
        });
        return getDataTable(list);
    }
    @Anonymous
    @ApiOperation(value = "酒店订单列表")
    @GetMapping("/hotelsOrderList")
    public TableDataInfo hotelsOrderList() {
        startPage();
        // /** 订单状态，1：未支付；2：已支付；3：已核销；4：已取消；5：退款中；6：已退款 */
        List<HotelsOrder> list = hotelsOrderService.list();
        list.forEach(hotelsOrder -> {
            if (hotelsOrder.getStatus().equals("1")){
                hotelsOrder.setStatus("未支付");
            }else if (hotelsOrder.getStatus().equals("2")){
                hotelsOrder.setStatus("已支付");
            }else if (hotelsOrder.getStatus().equals("3")){
                hotelsOrder.setStatus("已核销");
            }else if (hotelsOrder.getStatus().equals("4")){
                hotelsOrder.setStatus("已取消");
            }else if (hotelsOrder.getStatus().equals("5")){
                hotelsOrder.setStatus("退款中");
            }else if (hotelsOrder.getStatus().equals("6")){
                hotelsOrder.setStatus("已退款");
            }
        });
        return getDataTable(list);
    }


    @Anonymous
    @ApiOperation(value = "公告列表")
    @GetMapping("/noticeList")
    public TableDataInfo noticeList() {
        startPage();
        LambdaQueryWrapper<Notice> noticeLambdaQueryWrapper = new LambdaQueryWrapper<>();
        noticeLambdaQueryWrapper.eq(Notice::getNoticeStatus, "1");
        return getDataTable(noticeService.list(noticeLambdaQueryWrapper));

    }







}
